Skip to content

Conversation

DharmitD
Copy link
Member

@DharmitD DharmitD commented Sep 4, 2025

Description of your changes:

Fixes #11401

Adds support for the optional parameter to kfp.kubernetes.use_secret_as_env() and kfp.kubernetes.use_config_map_as_env() functions, bringing parity with the existing *_as_volume methods.

  • Python SDK: Added optional: bool = False parameter to both functions
  • Protobuf: Added optional field to SecretAsEnv and ConfigMapAsEnv messages
  • Backend: Updated driver to properly handle the optional field in Kubernetes resources
  • Tests: Added comprehensive test coverage for all optional field scenarios

Behavior

  • optional=False (default): Secret/ConfigMap must exist (backward compatible)
  • optional=True: Pod can start even if Secret/ConfigMap is missing
  • Follows Kubernetes EnvVarSource schema

Example Usage

import kfp.kubernetes as kubernetes

# Secret that must exist (current behavior - backward compatible)
kubernetes.use_secret_as_env(
    task,
    secret_name='required-secret',
    secret_key_to_env={'token': 'API_TOKEN'}
)

# Secret that's optional (new feature)
kubernetes.use_secret_as_env(
    task,
    secret_name='optional-secret',
    secret_key_to_env={'debug_key': 'DEBUG_TOKEN'},
    optional=True  # New parameter
)

This PR includes a cherry-picked commit from @rimolive 's past PR, that consisted of the SDK side changes. I've added backend changes and tests on top of those.

Checklist:

@DharmitD DharmitD marked this pull request as draft September 4, 2025 22:51
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch from a5d67de to 10cdb55 Compare September 4, 2025 23:01
DharmitD added a commit to DharmitD/data-science-pipelines-argo that referenced this pull request Sep 4, 2025
…ings

- Regenerate Python protobuf bindings to include the optional field for SecretAsEnv and ConfigMapAsEnv
- Update test_volume.py to expect optional: False in secretAsEnv
- Include backend driver code that handles optional field (from stash)
- All 110 kfp-kubernetes-library-tests now pass
- Fixes PR kubeflow#12216 test failures
DharmitD added a commit to DharmitD/data-science-pipelines-argo that referenced this pull request Sep 4, 2025
…ings

- Regenerate Python protobuf bindings to include the optional field for SecretAsEnv and ConfigMapAsEnv
- Update test_volume.py to expect optional: False in secretAsEnv
- Include backend driver code that handles optional field (from stash)
- All 110 kfp-kubernetes-library-tests now pass
- Fixes PR kubeflow#12216 test failures

Signed-off-by: ddalvi <[email protected]>
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch from d96ac32 to 3293763 Compare September 4, 2025 23:31
DharmitD added a commit to DharmitD/data-science-pipelines-argo that referenced this pull request Sep 5, 2025
…ndling

- Regenerate Python protobuf bindings to include the optional field for SecretAsEnv and ConfigMapAsEnv
- Update test_volume.py to expect optional: False in secretAsEnv
- Fix backend driver to only set Optional field when explicitly true (maintains backward compatibility)
- Prevents breaking existing backend tests that expect Optional to be nil by default
- All 110 kfp-kubernetes-library-tests now pass
- All backend driver tests now pass
- Fixes PR kubeflow#12216 test failures

Signed-off-by: ddalvi <[email protected]>
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch 2 times, most recently from d9c9b5b to a1bcee5 Compare September 6, 2025 00:47
DharmitD added a commit to DharmitD/data-science-pipelines-argo that referenced this pull request Sep 6, 2025
…ndling

- Regenerate Python protobuf bindings to include the optional field for SecretAsEnv and ConfigMapAsEnv
- Update test_volume.py to expect optional: False in secretAsEnv
- Fix backend driver to properly handle Optional field for all cases:
  * Not specified: Optional = nil → defaults to false in YAML (backward compatible)
  * Explicitly false: Optional = &false → optional: false in YAML
  * Explicitly true: Optional = &true → optional: true in YAML
- All 110 kfp-kubernetes-library-tests pass
- All backend driver tests pass
- Sample pipeline compilation tests pass with correct optional field handling
- Should fix KFP Samples test failures related to pod-spec-patch
- Fixes PR kubeflow#12216 test failures

Signed-off-by: ddalvi <[email protected]>
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch from a1bcee5 to e08a2b9 Compare September 6, 2025 02:41
@DharmitD DharmitD changed the title Add optional field for the secret/configmap as env vars feat(SDK+backend):Add optional field for the secret/configmap as env vars Sep 6, 2025
@DharmitD DharmitD changed the title feat(SDK+backend):Add optional field for the secret/configmap as env vars feat(SDK+backend): Add optional field for the secret/configmap as env vars Sep 6, 2025
@DharmitD DharmitD marked this pull request as ready for review September 8, 2025 15:43
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch from e08a2b9 to d0b11af Compare September 8, 2025 17:02
@mprahl
Copy link
Collaborator

mprahl commented Sep 10, 2025

/assign @HumairAK


// Name of the ConfigMap.
ml_pipelines.TaskInputsSpec.InputParameterSpec config_map_name_parameter = 3;
ml_pipelines.TaskInputsSpec.InputParameterSpec config_map_name_parameter = 4;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not change the numbers of pre-existing message fields, it will disrupt the wire format for the proto messages, keep the old fields as is and only increment the numbers for the newly added fields

it looks like the one in ConfigMapAsEnv accidentally skipped a number - it is what it is though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! Updated to keep the old fields as is, and have incremented numbers for the new "optional" fields.

Comment on lines +317 to +326
if secretAsEnv.Optional != nil {
secretKeySelector.Optional = secretAsEnv.Optional
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a unit test for this codepath?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added tests here.

@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch from d0b11af to b201949 Compare September 11, 2025 18:19
@google-oss-prow google-oss-prow bot added size/XL and removed size/L labels Sep 11, 2025
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch 2 times, most recently from 91d0e48 to 3996e21 Compare September 11, 2025 19:05
rimolive and others added 2 commits September 11, 2025 15:57
…iables

- Update protobuf definitions and regenerate bindings
- Fix backend driver to handle Optional field correctly
- Update tests and ensure backward compatibility

Signed-off-by: ddalvi <[email protected]>
@DharmitD DharmitD force-pushed the apply-pr-11486-changes branch from 3996e21 to 70fc60d Compare September 11, 2025 19:58
@HumairAK
Copy link
Collaborator

/lgtm
/approve

@google-oss-prow google-oss-prow bot added the lgtm label Sep 12, 2025
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: HumairAK

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 55ec846 into kubeflow:master Sep 12, 2025
93 checks passed
krishanbhasin-px pushed a commit to krishanbhasin-px/kubeflow-pipelines that referenced this pull request Sep 18, 2025
… vars (kubeflow#12216)

* Add optional field for the secret/configmap as env vars

Signed-off-by: ddalvi <[email protected]>

* Add tests for the optional field for secret/configmap environment variables

- Update protobuf definitions and regenerate bindings
- Fix backend driver to handle Optional field correctly
- Update tests and ensure backward compatibility

Signed-off-by: ddalvi <[email protected]>

---------

Signed-off-by: ddalvi <[email protected]>
Co-authored-by: Ricardo M. Oliveira <[email protected]>
aniketpati1121 pushed a commit to aniketpati1121/Kubeflow-pipelines that referenced this pull request Sep 22, 2025
… vars (kubeflow#12216)

* Add optional field for the secret/configmap as env vars

Signed-off-by: ddalvi <[email protected]>

* Add tests for the optional field for secret/configmap environment variables

- Update protobuf definitions and regenerate bindings
- Fix backend driver to handle Optional field correctly
- Update tests and ensure backward compatibility

Signed-off-by: ddalvi <[email protected]>

---------

Signed-off-by: ddalvi <[email protected]>
Co-authored-by: Ricardo M. Oliveira <[email protected]>
aniketpati1121 pushed a commit to aniketpati1121/Kubeflow-pipelines that referenced this pull request Sep 24, 2025
… vars (kubeflow#12216)

* Add optional field for the secret/configmap as env vars

Signed-off-by: ddalvi <[email protected]>

* Add tests for the optional field for secret/configmap environment variables

- Update protobuf definitions and regenerate bindings
- Fix backend driver to handle Optional field correctly
- Update tests and ensure backward compatibility

Signed-off-by: ddalvi <[email protected]>

---------

Signed-off-by: ddalvi <[email protected]>
Co-authored-by: Ricardo M. Oliveira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Allow kfp.kubernetes to set optional=True on Secrets and ConfigMaps as environment variables
4 participants